define(function(require, exports,modules){

  	var $ = require('../lib/jquery');  // jquery模块
  	var bs = require('../lib/bootstrap-3.0.0-dist/dist/js/bootstrap');
	 var _ = require('../main');  // main模块

   var commonurl=_.getUrl();
   var ticket = _.getTicket();
   var filePath;
   var port;

	$(".table_detail").show();

  //ajax数据交互
  $.ajax({ 
    url:commonurl+"nginx/getSystem",
    type: 'GET', 
    headers: {"Authorization":ticket},
  //data:{username:$("#username").val(), content:$("#content").val()}, 
    success: function(json){
         parameters=json;
        filePath=_.getFilePath(parameters[0].value);
        port=parameters[1].value;
        //遍历表格
        $.each(parameters, function(commentIndex, comment){
        	//动态展示表单
        	// if(parameters[commentIndex].disabled==0)
        	// {
         //   		var templates="<span>"+parameters[commentIndex].name+"：</span><span><input type='text' name='' class='form-control' value='"+parameters[commentIndex].value+"'></span>";
         //    }
         //    else{
         //    	var templates="<span>"+parameters[commentIndex].name+"：</span><span><input type='text' name='' disabled='disabled' class='form-control' value='"+parameters[commentIndex].value+" '></span>";
         //    }
         var templates="<span>"+parameters[commentIndex].name+"：</span><span><input type='text' id='systemId"+commentIndex+"' class='form-control' value='"+parameters[commentIndex].value+"'></span>";
            $(".box .table_detail .double_control").append(templates);
           
         });
      },
      error:function(){
         var templates="<span>安装路径：</span><span><input type='text' name='' class='form-control' value=''></span>";
         var template="<span>端口号：</span><span><input type='text' name='' class='form-control' value=''></span>";
         $(".box .table_detail .double_control").append(templates);
         $(".box .table_detail .double_control").append(template);
      }
    });
//启动nginx点击事件
    $(".btn_power").click(function(){
        $.ajax({
              url:commonurl+"nginx/star?address="+filePath+"&point="+port,
              type: 'GET',
              headers: {"Authorization":ticket}, 
              Accept: 'application/json',
              async: false,//设置为同步传输
              success: function(XMLHttpRequest, textStatus){
                confirm("提示",textStatus);
              },
              error:function(textStatus){
                confirm("提示",textStatus);
              }
        });
    });   
//启动nginx点击事件updateSystem
    $(".btn_stop").click(function(){
        $.ajax({
              url:commonurl+"nginx/stop?address="+filePath+"&point="+port,
              type: 'GET',
              headers: {"Authorization":ticket}, 
              Accept: 'application/json',
              success: function(XMLHttpRequest, textStatus){
                confirm("提示",textStatus);
              },
              error:function(textStatus){
                confirm("提示",textStatus);
              }
        });
    }); 
    //启动nginx点击初始化事件
    $(".btn_init").click(function(){
        $.ajax({
              url:commonurl+"nginx/init?address="+filePath,
              type: 'GET', 
              headers: {"Authorization":ticket},
              Accept: 'application/json',
              success: function(json){
                confirm("提示",json);
              },
              error:function(json){
                confirm("提示",json);
              }
        });
    });     
    $(".btn_team").click(function(){
        
        $.each(parameters, function(commentIndex, comment){
          confValue=$("#systemId"+commentIndex).val();
        $.ajax({ 
            url: commonurl+"nginx/updateSystem",
            type: 'POST', 
            headers: {"Authorization":ticket},
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify({"id":parameters[commentIndex].id,"name":parameters[commentIndex].name,"value":confValue}), 
              success: function(json){
                    alert("新建成功");
                    setTimeout(function(){  //使用  setTimeout（）方法设定定时1000毫秒
                               window.location.reload();//页面刷新
                    },1000);

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                  alert("系统错误");
                      }
              });
      });
    })
});